<?php
include_once "lib/config.php";
include_once "header.php";

if(!isset($_POST['job_id']) || $_POST['job_id']==0)
{
    redirect("careerjobs.php");
}

if(isset($_SESSION['msg_success']) && $_SESSION['msg_success']!="")
{
	$msg_success=$_SESSION['msg_success'];
	unset($_SESSION['msg_success']);
}

if(isset($_SESSION['msg_error']) && $_SESSION['msg_error']!="")
{
	$msg_error=$_SESSION['msg_error'];
	unset($_SESSION['msg_error']);
}

if(!isset($_POST['order_by']))
{
	$_POST['order_by']="asc";
}

if(!isset($_POST['type_title']))
{
	$_POST['type_title']="applied_date";
}

if(!isset($_POST['pid']))	// code starts for implementing pagination 
{
	$_POST['pid']=1;
}

$selectquery="select af_career_postapplications.*,Email_ID,Full_Name,cat_name,post_name from af_careers,af_users,af_categories,af_career_postapplications where af_users.User_ID=af_career_postapplications.user_id and af_career_postapplications.careerpost_id=af_careers.id and af_careers.cat_id=af_categories.id and af_career_postapplications.careerpost_id=:postid ";
$conditionarr=array(":postid"=>$_POST['job_id']);

if(isset($_POST['searchText']) && $_POST['searchText']!="" && isset($_POST['filterby']) && $_POST['filterby']!="")
{
    $selectquery.=" and ".$_POST['filterby']." like :".$_POST['filterby'];
	$conditionarr[":".$_POST['filterby']]= "%".$_POST['searchText']."%";
}

$totalrecords=DB::fetch_num_of_rows(DB::query($selectquery,$conditionarr));

$selectquery.=" order by ".$_POST['type_title']." ".$_POST['order_by']." limit ".(($_POST['pid']-1)*PAGELIMIT).", ".PAGELIMIT;

$jobpostinfo=DB::fetch_array(DB::query($selectquery,$conditionarr));

include_once "lib/paginate_class.php";

$paging_obj=new Paginate();

$pagingdiv=$paging_obj->getnewpager($_POST['pid'],$totalrecords);


?>
        
		<div class="container_12">
        
            <div class="bottom-spacing">
                	
                    <div class="grid_12">
        		    <fieldset>
        		    	
        		        <input class="submit-gray" type="button" value="Back" onclick="window.location='careerjobs.php'" />
        		    </fieldset>
        		    </div>
                    <br/>
                    <br>
                    <form name="mainform" method="post">
	                    <!-- Table records filtering -->
	                    Filter By: 
	                    <select class="input-short" style="width:200px;" name="filterby" id="filterby">
	                    	<option value="" selected="selected">Select filter</option>
	                        <option value="post_name"  <?php if(isset($_POST['filterby']) && $_POST['filterby']=="post_name"){ echo "selected"; } ?> >Job Post Name</option>
                            <option value="Email_ID"  <?php if(isset($_POST['filterby']) && $_POST['filterby']=="Email_ID"){ echo "selected"; } ?> >Email ID</option>
	                    </select>
	                    &nbsp;&nbsp;&nbsp;&nbsp;
	                    <input type="text" class="input-short" style="width:300px;" name="searchText" id="searchText" value="<?php if(isset($_POST['searchText'])){ echo $_POST['searchText']; } ?>">
	                    &nbsp;&nbsp;
	                    <input type="button" class="submit-green" value="Search" onclick="return getempfilterresults();"> &nbsp;&nbsp;<input type="button" class="submit-green" value="Show All" onclick="document.getElementById('filterby').value='';document.getElementById('searchText').value='';document.mainform.submit();">
	                    <input type="hidden" id="job_id" name="job_id" value="<?php if(isset($_POST['job_id'])){ echo $_POST['job_id']; } ?>" />
	                    <input type="hidden" name="opt_status" id="opt_status">
						<input type="hidden" name="pid" id="pid" value="<?php if(isset($_POST['pid']))echo $_POST['pid']; ?>">
						<input type="hidden" name="type_title" id="type_title" value="<?php if(isset($_POST['type_title']))echo $_POST['type_title']; ?>">
						<input type="hidden" name="order_by" id="order_by" value="<?php if(isset($_POST['order_by']))echo $_POST['order_by']; ?>">
						
					</form>
                	<br>
            </div>
            
            
                <!-- Example table -->
                <div class="module" style="width:100% !important;">
                	<h2><span>Job Posts List</span></h2>
                    
                    <div class="module-table-body">
                    	
                        <table id="myTable" >
                        	<thead>
                                <tr>
                                    <th style="width:10%">Sr.No.</th>
                                    <th style="width:15%"><a href="javascript:void(0)" onclick="return change_order('post_name','<?php echo $_POST['order_by'] ?>')" >Post Name</a></th>
                                    <th style="width:15%"><a href="javascript:void(0)" onclick="return change_order('cat_name','<?php echo $_POST['order_by'] ?>')" >Job Post Category</a></th>
                                    <th style="width:15%"><a href="javascript:void(0)" onclick="return change_order('Email_ID','<?php echo $_POST['order_by'] ?>')" >Email ID</a></th>
                                    <th style="width:15%"><a href="javascript:void(0)" onclick="return change_order('Full_Name','<?php echo $_POST['order_by'] ?>')" >Full Name</a></th>
                                    <th style="width:10%"><a href="javascript:void(0)" onclick="return change_order('applied_date','<?php echo $_POST['order_by'] ?>')" >Applied Date</a></th>
                                    <th style="width:15%"><a href="javascript:void(0)" >Resume</a></th>
                                    
                                </tr>
                            </thead>
                            <tbody>
                            <?php
                            if(count($jobpostinfo)>0)
                            {
                            	$count=0;
                            	for($i=0;$i<count($jobpostinfo);$i++)
                            	{
                            		$count++;
                            ?>
							    <tr <?php if($count%2==0)echo "class='odd'"; else echo "class='even'"; ?>>
                                    <td class="align-center"><?php echo ($i+1);  ?></td>
                                    <td><?php echo $jobpostinfo[$i]['post_name']; ?></td>
                                    <td><?php echo trim($jobpostinfo[$i]['cat_name']); ?></td>
                                    <td><?php echo $jobpostinfo[$i]['Email_ID'];  ?></td>
                                    <td><?php echo $jobpostinfo[$i]['Full_Name'];  ?></td>
                                    <td><?php echo date("d/m/Y",trim($jobpostinfo[$i]['applied_date'])); ?></td>
                                    <td><a href="download.php?filename=../uploads/postresume/<?php echo $jobpostinfo[$i]['resume_url']; ?>"><?php echo $jobpostinfo[$i]['resume_url'];  ?></a></td>
                                    
                                </tr>
                            <?php
                            	}
                            }
                            else
                            {
								?>
								<tr>
									<td colspan="8"><span class="redspan">There is no record found!!!</span></td>
								</tr>
								<?php	
							}
                            ?>
                            </tbody>
                        </table>
                        <br>
                        <?php echo $pagingdiv; ?>
                        
                        <div style="clear: both"></div>
                     </div> <!-- End .module-table-body -->
                </div> <!-- End .module -->
                
                
            
            <div style="clear:both;"></div>
            
            
        </div> <!-- End .container_12 -->
		
<?php include_once("footer.php"); ?>   
<?php
if(isset($msg_success) && $msg_success!="")
{
	$notymessage=$msg_success;
	$msgtype="success";
}
else if(isset($msg_error) && $msg_error!="")
{
	$msgtype="error";
	$notymessage=$msg_error;
}
else
{
	$msgtype="";
}
if($msgtype!="")
{
?>        
<script language="javascript">
	$(document).ready(function(){
		
		var options = $.parseJSON('{"text":"<?php echo $notymessage; ?>","layout":"top","type":"<?php echo $msgtype; ?>"}');
		noty(options);
		
	});
</script>  
<?php
}
?>     